import pandas as pd
from datetime import datetime, date, timedelta

# 读取源数据
df = pd.read_excel('source.xlsx')

# 初始化新列表
new_data = []

for index, row in df.iterrows():
    year = row['年份']
    month = row['月份']
    revenue = row['收费']
    
    start_date = date(year, month, 1)
    
    # 计算当月的最后一天
    if month == 12:
        end_year = year + 1
        end_month = 1
    else:
        end_year = year
        end_month = month + 1
    
    end_date = date(end_year, end_month, 1) - timedelta(days=1)
    
    new_data.append([year, month, revenue, start_date, end_date])

# 创建新的DataFrame
columns = ['年份', '月份', '收费', '开始日期', '结束日期']
new_df = pd.DataFrame(new_data, columns=columns)

# 将结果写入新的Excel文件
new_df.to_excel('output.xlsx', index=False)
print('已将结果写入 output.xlsx 文件')